home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #48 (Sep 89) / Zoundz Source / HandleTheMenus.Pas < prev    next >
Pascal/Delphi Source File  |  1989-05-01  |  6KB  |  227 lines

  1. unit HandleTheMenus;
  2.  
  3. interface
  4.  
  5.     uses
  6.         PrintTraps, Message, save_changes, About, Untitled, Sound, MyGlobals, MyFileStuff, MyPrintStuff;
  7.  
  8.     procedure AdjustMenus;
  9.     procedure Handle_My_Menu (var doneFlag: boolean; theMenu, theItem: integer);{Handle menu selection}
  10.  
  11. implementation
  12.  
  13.     procedure AdjustMenus;
  14.     begin
  15.         if (FrontWindow <> MyWindow) then
  16.             begin {Something up there}
  17.                 DisableItem(M_Extend, 0);
  18.                 EnableItem(M_Edit, 0);
  19.  
  20.                 DisableItem(M_File, MI_Open);
  21.                 DisableItem(M_File, MI_New);
  22.                 DisableItem(M_File, MI_Close);
  23.                 DisableItem(M_File, MI_Save);
  24.                 DisableItem(M_File, MI_Save_As);
  25.                 DisableItem(M_File, MI_Page_Setup);
  26.                 DisableItem(M_File, MI_Print);
  27.             end
  28.         else if MyWindow <> nil then
  29.             begin {My Window up there}
  30.                 EnableItem(M_Extend, 0);
  31.                 DisableItem(M_Edit, 0);
  32.  
  33.                 DisableItem(M_File, MI_Open);
  34.                 DisableItem(M_File, MI_New);
  35.                 EnableItem(M_File, MI_Close);
  36.                 EnableItem(M_File, MI_Save);
  37.                 EnableItem(M_File, MI_Save_As);
  38.                 EnableItem(M_File, MI_Page_Setup);
  39.                 EnableItem(M_File, MI_Print);
  40.             end
  41.         else
  42.             begin {nothing up there}
  43.                 VolRefNum := 0; {no need to save any changes}
  44.                 DisableItem(M_Extend, 0);
  45.                 DisableItem(M_Edit, 0);
  46.  
  47.                 EnableItem(M_File, MI_Open);
  48.                 EnableItem(M_File, MI_New);
  49.                 DisableItem(M_File, MI_Close);
  50.                 DisableItem(M_File, MI_Save);
  51.                 DisableItem(M_File, MI_Save_As);
  52.                 DisableItem(M_File, MI_Page_Setup);
  53.                 DisableItem(M_File, MI_Print);
  54.             end;
  55.     end;
  56.  
  57.     procedure Handle_My_Menu;           {Handle menu selections realtime}
  58.  
  59.         var
  60.             DNA: integer;              {For opening DAs}
  61.             BoolHolder: boolean;       {For SystemEdit result}
  62.             DAName, title: Str255;            {For getting DA name}
  63.             SavePort: GrafPtr;         {Save current port when opening DAs}
  64.             i, theValue: integer;
  65.  
  66.     begin                           {Start of procedure}
  67.  
  68.         case theMenu of         {Do selected menu list}
  69.  
  70.             L_Apple: 
  71.                 begin
  72.                     case theItem of
  73.                         MI_About_Zoundz: 
  74.                             begin
  75.                                 D_About;
  76.                             end;
  77.                         otherwise{Handle the DAs}
  78.                             begin
  79.                                 GetPort(SavePort);
  80.                                 GetItem(AppleMenu, theItem, DAName);
  81.                                 DNA := OpenDeskAcc(DAName);
  82.                                 SetPort(SavePort);
  83.                             end;
  84.                     end;            {End of item case}
  85.                 end;                {End for Apple Menu list}
  86.  
  87.             L_File: 
  88.                 begin
  89.                     case theItem of
  90.                         MI_New: 
  91.                             begin
  92.                                 Init_Untitled;
  93.                                 Open_Untitled;
  94.                                 dirty := false;
  95.                             end;
  96.                         MI_Open: 
  97.                             begin
  98.                                 doOpen;
  99.                                 if VolRefNum <> 0 then
  100.                                     begin
  101.                                         Open_Untitled;
  102.                                         SetWTitle(MyWindow, FileName);
  103.                                         dirty := false;
  104.                                     end;
  105.                             end;
  106.                         MI_Close: 
  107.                             begin
  108.                                 if dirty then
  109.                                     begin {need saving}
  110.                                         GetWTitle(MyWindow, title);
  111.                                         ParamText(title, '', '', '');
  112.                                         theValue := D_save_changes;
  113.                                         if (theValue = I_Yes) then
  114.                                             begin {wants to save changes}
  115.                                                 if VolRefNum = 0 then
  116.                                                     doSaveAs
  117.                                                 else
  118.                                                     doSave;
  119.                                                 if VolRefNum <> 0 then {did not cancel saving}
  120.                                                     Close_Untitled(MyWindow);
  121.                                             end
  122.                                         else if theValue = I_No then
  123.                                             Close_Untitled(MyWindow);
  124.                                     end {of needing saved}
  125.                                 else {no need to save}
  126.                                     Close_Untitled(MyWindow);
  127.                             end;
  128.                         MI_Save: 
  129.                             begin
  130.                                 if VolRefNum = 0 then
  131.                                     doSaveAs
  132.                                 else
  133.                                     doSave;
  134.                                 if VolRefNum <> 0 then
  135.                                     dirty := false;
  136.                             end;
  137.                         MI_Save_As: 
  138.                             begin
  139.                                 doSaveAs;
  140.                                 if VolRefNum <> 0 then
  141.                                     dirty := false;
  142.                             end;
  143.                         MI_Page_Setup: 
  144.                             begin
  145.                                 doSetUp;
  146.                             end;
  147.                         MI_Print: 
  148.                             begin
  149.                                 doPrint;
  150.                             end;
  151.                         MI_Quit: 
  152.                             begin
  153.                                 if (MyWindow <> nil) and dirty then
  154.                                     begin {need saving}
  155.                                         GetWTitle(MyWindow, title);
  156.                                         ParamText(title, '', '', '');
  157.                                         theValue := D_save_changes;
  158.                                         case theValue of
  159.                                             I_Yes: 
  160.                                                 begin
  161.                                                     if VolRefNum = 0 then
  162.                                                         doSaveAs
  163.                                                     else
  164.                                                         doSave;
  165.                                                     if VolRefNum <> 0 then {did not cancel saving}
  166.                                                         doneFlag := TRUE;
  167.                                                 end; {of Yes}
  168.                                             I_No: 
  169.                                                 doneFlag := True;
  170.                                             otherwise
  171.                                                 ;
  172.                                         end; {of case}
  173.                                     end {of needing saved}
  174.                                 else {no need to save}
  175.                                     doneFlag := TRUE;
  176.                             end;
  177.                         otherwise
  178.                             ;
  179.                     end; {of item list}
  180.                 end; {of File Menu List }
  181.  
  182.             L_Edit: 
  183.                 begin
  184.                     BoolHolder := SystemEdit(theItem - 1); {DA Editing}
  185.                 end;
  186.  
  187.             L_Extend: 
  188.                 begin
  189.                     case theItem of{Handle extending values}
  190.                         MI_Frequency: 
  191.                             begin
  192.                                 theValue := MyDoc^.freq[NoteIndex];
  193.                                 for i := MyDoc^.StartValue to MyDoc^.EndValue do
  194.                                     MyDoc^.freq[i] := theValue;
  195.                             end; {of Frequency}
  196.                         MI_Amplitude: 
  197.                             begin
  198.                                 theValue := MyDoc^.amp[NoteIndex];
  199.                                 for i := MyDoc^.StartValue to MyDoc^.EndValue do
  200.                                     MyDoc^.amp[i] := theValue;
  201.                             end; {of Amplitude}
  202.                         MI_Duration: 
  203.                             begin
  204.                                 theValue := MyDoc^.dur[NoteIndex];
  205.                                 for i := MyDoc^.StartValue to MyDoc^.EndValue do
  206.                                     MyDoc^.dur[i] := theValue;
  207.                             end; {of duration}
  208.                         MI_Timbre: 
  209.                             begin
  210.                                 theValue := MyDoc^.timbre[NoteIndex];
  211.                                 for i := MyDoc^.StartValue to MyDoc^.EndValue do
  212.                                     MyDoc^.timbre[i] := theValue;
  213.                             end; {of timbre}
  214.                         otherwise
  215.                             ;
  216.                     end; { of items in Extend Menu}
  217.                     InvalRect(NotePallete);
  218.                 end; {of Extend Menu List}
  219.  
  220.             otherwise
  221.                 ;
  222.         end;                        {End for the Menus}
  223.  
  224.         HiliteMenu(0);              {Turn menu selection off}
  225.     end;                            {End of procedure Handle_My_Menu}
  226.  
  227. end.                                    {End of unit}